<template>
  <Dialog v-model="dialogVisible" :title="dialogTitle">
    <el-table :data="infoShowList">
      <el-table-column prop="filed" label="字段名称" show-overflow-tooltip />
      <el-table-column label="是否显示" show-overflow-tooltip>
        <template #default="scope">
          <div>
            <el-radio-group v-model="scope.row.show">
              <el-radio :label="1">显示</el-radio>
              <el-radio :label="0">不显示</el-radio>
            </el-radio-group>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="查询条件中显示" show-overflow-tooltip v-if="props.showQuery">
        <template #default="scope">
          <div>
            <el-radio-group v-model="scope.row.query">
              <el-radio :label="1">显示</el-radio>
              <el-radio :label="0">不显示</el-radio>
            </el-radio-group>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <template #footer>
      <el-button type="primary" @click="submitForm">确定</el-button>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </template>
  </Dialog>
</template>
<script lang="ts" setup>
import * as infoShowApi from '@/api/infoShow/index'

const props = defineProps({
  showQuery: {
    type: Boolean,
    default: true
  }
})

const router = useRouter()
const message = useMessage() // 消息弹窗

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题

/** 打开弹窗 */
const open = async (type: string) => {
  dialogVisible.value = true
  dialogTitle.value = '信息展示设置'
  getInfoShowConf(type)
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
const submitForm = async () => {
  const data = await infoShowApi.infoShowUpdateBatch(infoShowList.value)
  if (data) {
    dialogVisible.value = false
    message.success('操作成功')
    emit('success')
  }
}

const infoShowList = ref()
const getInfoShowConf = async (type) => {
  const data = await infoShowApi.infoShowList({
    type,
    language: location.href.indexOf('/en/') >= 0 ? 'en' : ''
  })
  infoShowList.value = data
}
</script>
